package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.project.entity.FinanceMoneyStatementDetailsEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;
import com.yuexunit.util.DateUtil;
import com.yuexunit.util.StringUtil;

/**
 * @author wenwenlong
 */
@Implements(FinanceMoneyStatementDetailsService.class)
public class FinanceMoneyStatementDetailsServiceImpl implements FinanceMoneyStatementDetailsService {

	@Override
	@Transactional
	public Long createFinanceMoneyStatementDetails(FinanceMoneyStatementDetailsEntity entity) {
		entity.setCreateDateTime(DateUtil.now());
		PersistUtil.insert(entity);
		return entity.getDetailsId();
	}

	@Override
	@Transactional
	public void updateFinanceMoneyStatementDetails(FinanceMoneyStatementDetailsEntity entity) {
		PersistUtil.update(entity);
	}

	@Override
	@Transactional
	public void deleteFinanceMoneyStatementDetails(Long detailsId) {
		PersistUtil.delete(FinanceMoneyStatementDetailsEntity.class, detailsId);
	}

	@Override
	public FinanceMoneyStatementDetailsEntity inquireFinanceMoneyStatementDetails(Long detailsId) {
		return PersistUtil.get(FinanceMoneyStatementDetailsEntity.class, detailsId);
	}

	@Override
	public List<FinanceMoneyStatementDetailsEntity> inquireFinanceMoneyStatementDetailsList(Long moneyStatementId, Long pickupId, String expenseName) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceMoneyStatementDetailsEntity.class);
		if (null != moneyStatementId) {
			criteria.add(Restrictions.eq("moneyStatementId", moneyStatementId));
		}
		if (null != pickupId) {
			criteria.add(Restrictions.eq("pickupId", pickupId));
		}
		if (StringUtil.isNotBlank(expenseName)) {
			criteria.add(Restrictions.eq("expenseName", expenseName));
		}
		return PersistUtil.get(criteria);
	}

}
